/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cardgame.game.monsters;

import cardgame.game.*;
import cardgame.game.events.*;

/**
 *
 * @author Carl
 */
public class Nami extends MonsterCard{

    public Nami(){
        description = new Description("Nami", "Fish");
        manaTypes = new Mana[]{Mana.BLUE};
        summonCost = new Cost(new ManaAmount(Mana.BLUE, 1), 0, false);
        attackDamage = 1;
        setLifepoints(1);
        setSpells(new Spell[]{new Spell(){{
                description = new Description("Tidecaller's Blessing");
                cost = new Cost(new ManaAmount(Mana.BLUE, 1), 0, false);
                spellParameterFormat = new SpellParameterFormat(){{
                    add("Choose the target to buff.", SpellParameterFormat_Entry.Type.MONSTER, SpellParameterFormat_Entry.Owner.ALLIED);
                }};
            }

            @Override
            public void cast(Game game, SpellParameter[] parameters){
                final MonsterCard target = getParameter_Monster(parameters[0]);
                game.addEventListener(new EventListener(){

                    @Override
                    public boolean preEvent(Game game, Event receivedEvent){
                        return true;
                    }

                    @Override
                    public void postEvent(Game game, Event receivedEvent){
                        if(receivedEvent instanceof AttackMonsterEvent){
                            AttackMonsterEvent event = (AttackMonsterEvent) receivedEvent;
                            if(event.getAttackingMonsterCard() == target){
                                game.triggerEvent(new AddMonsterCurrentLifepointsEvent(event.getTargetMonsterCard(), -1));
                            }
                        }
                        else if(receivedEvent instanceof AttackPlayerEvent){
                            AttackPlayerEvent event = (AttackPlayerEvent) receivedEvent;
                            if(event.getAttackingMonsterCard() == target){
                                game.triggerEvent(new AddPlayerLifepointsEvent(event.getTargetPlayer(), -1));
                            }
                        }
                        else if(receivedEvent instanceof TurnEndEvent){
                            game.removeEventListener(this);
                        }
                    }
                });
            }
        }});
    }
}
